$(document).ready(function () {

	CKEDITOR.replace( 'article_header', {
		toolbar : 'Basic'
	});
	
	CKEDITOR.replace( 'article_content', {
		extraPlugins : 'autogrow',
		removePlugins : 'resize'
	});
			
	$('#set_form').validate({
		
		submitHandler: function() {
		
			$('#article_header').val(CKEDITOR.instances.article_header.getData());
			$('#article_content').val(CKEDITOR.instances.article_content.getData());
		
			$('#set_form').ajaxSubmit({
				beforeSubmit: function() {
				},
				dataType: 'json',
				success: function(e) {
				
					if(e.result) {
						$('#set_form').fadeOut();
						$('#set_message').html('<div class="success">'+e.message+'</div>');
						$('#set_message').fadeIn();
						setTimeout("$('#set_message').html('<div class=\"success\">Redirection ...</div>')", 2000);
						setTimeout("window.location.href = '"+$('#redirection').val()+"'", 2000);
					
					} else {
					
						$('#set_message').html('<div class="error">'+e.message+'</div>');
						$('#set_message').show();
						$('#set_send').removeAttr('disabled');
						setTimeout("$('#set_message').fadeOut()", 2000);
				
					}
				},
				error: function(e) {
					alert(e);
					$('#set_send').removeAttr('disabled');
				}
			
			});
		
		}
	
	});
	
});
